#include <iostream>
#include <string>
using namespace std;

class Solution 
{
public:
	int firstUniqChar(string s) 
	{
		int len = s.size();
		char uniqueChar = '\0';
		int i = 0;
		int j = 0;
		int flag = 1;
		for (i = 0; i < len; i++)
		{
			if (s[i] != '\0')
			{
				flag = 1;
				uniqueChar = s[i];
				for (j = i + 1; j < len; j++)
				{
					if (s[j] == s[i])
					{
						s[j] = '\0';
						flag = 0;
					}
				}
				
				if (flag == 1)
				{
					break;
				}
			}
			
		}
		
		if (i == len)
		{
			return -1;
		}
		return i;
	}
};

// 哈希思想
class Solution2
{
public:
	int firstUniqChar(string s) 
	{
		// 计数
		int count[26] = { 0 };
		for (auto ch : s)
		{
			++count[ch - 'a'];
		}
		
		// 确定唯一
		for (int i = 0; i < s.size(); i++)
		{
			if (count[s[i] - 'a'] == 1)
			{
				return i;
			}
		}
		
		return -1;
	}
};

int main()
{
	string s1("leetcode");
	Solution solution;
	cout << solution.firstUniqChar(s1) << endl;
	
	Solution2 solution2;
	cout << solution2.firstUniqChar(s1) << endl;
	
	//cout << s1[1] << endl;
	
	return 0;
}
